class MyStack {
    Queue<Integer> InQueue;
    Queue<Integer> OutQueue;
    public MyStack() {
        InQueue = new LinkedList<>();
        OutQueue = new LinkedList<>();
    }
    
    public void push(int x) {
        InQueue.offer(x);
        while(!OutQueue.isEmpty()){
            InQueue.offer(OutQueue.poll());
        }
        //交换输入输出队使得输入队列在没有push的时候为空
        Queue temp = InQueue;
        InQueue = OutQueue;
        OutQueue = temp;
    }
    
    public int pop() {
        return OutQueue.poll();
    }
    
    public int top() {
        return OutQueue.peek();
    }
    
    public boolean empty() {
         return OutQueue.isEmpty();
    }
}

/**
 * Your MyStack object will be instantiated and called as such:
 * MyStack obj = new MyStack();
 * obj.push(x);
 * int param_2 = obj.pop();
 * int param_3 = obj.top();
 * boolean param_4 = obj.empty();
 */